package com.example.newinfinity.View.DrawShape

import android.graphics.Canvas
import android.graphics.Paint

//画线段
class LineShape() : Shape() {
    override fun draw(canvas: Canvas) {
        //绘制线段时需调整画笔的style
        mPaint.style = Paint.Style.STROKE
        canvas.drawLine(startX, startY, endX, endY, mPaint)

        //继承父类 拖拉点拽状态为selected时显示边框及四个拖拉圆点
        super.draw(canvas)
    }

    override fun containsPointInPath(x: Float, y: Float): Boolean {
        val a = (startX - x) * (startX - x) + (startY - y) * (startY - y)
        val reallyA = Math.sqrt(a.toDouble())
        val b = (endX - x) * (endX - x) + (endY - y) * (endY - y)
        val reallyB = Math.sqrt(b.toDouble())
        val lineLength = (startX - endX) * (startX - endX) + (startY - endY) * (startY - endY)
        val reallyLineLength = Math.sqrt(lineLength.toDouble())
        return if (reallyA+reallyB < reallyLineLength + 1) {
            true
        } else {
            false
        }
        /*return super.containsPoint(x, y)*/
    }
}